From 957baf211d21cf10ef0c796fbc422c38dfde2028 Mon Sep 17 00:00:00 2001 From: tsteven4 <13596209+tsteven4@users.noreply.github.com> Date: Sun, 31 Jul 2022 11:59:34 -0600 Subject: [PATCH] return QString from html_entitize, xml_entitize. (#897) --- defs.h | 4 ++-- html.cc | 27 ++++++++++----------------- kml.cc | 6 ++---- osm.cc | 8 ++++---- util.cc | 12 +++++++----- 5 files changed, 25 insertions(+), 32 deletions(-) diff --git a/defs.h b/defs.h index e78886083..352c65a33 100644 --- a/defs.h +++ b/defs.h @@ -1079,8 +1079,8 @@ QDateTime dotnet_time_to_qdatetime(long long dotnet); const char* get_cache_icon(const Waypoint* waypointp); const char* gs_get_cachetype(geocache_type t); const char* gs_get_container(geocache_container t); -char* xml_entitize(const char* str); -char* html_entitize(const QString& str); +QString xml_entitize(const QString& str); +QString html_entitize(const QString& str); char* strip_html(const utf_string*); char* strip_nastyhtml(const QString& in); char* convert_human_date_format(const char* human_datef); /* "MM,YYYY,DD" -> "%m,%Y,%d" */ diff --git a/html.cc b/html.cc index 8f3c07735..e84507f71 100644 --- a/html.cc +++ b/html.cc @@ -75,10 +75,9 @@ HtmlFormat::html_disp(const Waypoint* wpt) const gbfprintf(file_out, "
\n"); if (wpt->description != wpt->shortname) { if (wpt->HasUrlLink()) { - char* d = html_entitize(wpt->description); - UrlLink link = wpt->GetUrlLink(); - gbfprintf(file_out, "%s", CSTR(link.url_), d); - xfree(d); + gbfputs(QStringLiteral("%2") + .arg(wpt->GetUrlLink().url_, html_entitize(wpt->description)), + file_out); } else { gbfprintf(file_out, "%s", CSTR(wpt->description)); } @@ -139,9 +138,9 @@ HtmlFormat::html_disp(const Waypoint* wpt) const logpart = xml_findfirst(curlog, "groundspeak:finder"); if (logpart) { - char* f = html_entitize(logpart->cdata); - gbfprintf(file_out, "%s on ", f); - xfree(f); + gbfputs(QStringLiteral("%1 on ") + .arg(html_entitize(logpart->cdata)), + file_out); } logpart = xml_findfirst(curlog, "groundspeak:date"); @@ -178,9 +177,7 @@ HtmlFormat::html_disp(const Waypoint* wpt) const s = logpart->cdata; } - char* t = html_entitize(s); - gbfputs(t, file_out); - xfree(t); + gbfputs(html_entitize(s), file_out); } gbfprintf(file_out, "

\n"); @@ -194,13 +191,9 @@ HtmlFormat::html_disp(const Waypoint* wpt) const void HtmlFormat::html_index(const Waypoint* wpt) const { - char* sn = html_entitize(wpt->shortname); - char* d = html_entitize(wpt->description); - - gbfprintf(file_out, "%s - %s
\n", sn, sn, d); - - xfree(sn); - xfree(d); + gbfputs(QStringLiteral("%1 - %2
\n") + .arg(html_entitize(wpt->shortname), html_entitize(wpt->description)), + file_out); } void diff --git a/kml.cc b/kml.cc index fbb5b04ca..bf56c1dff 100644 --- a/kml.cc +++ b/kml.cc @@ -1238,10 +1238,8 @@ QString KmlFormat::kml_geocache_get_logs(const Waypoint* wpt) const s = logpart->cdata; } - r = r + "
"; - char* t = html_entitize(s); - r = r + t; - xfree(t); + r += "
"; + r += html_entitize(s); } r += "

"; diff --git a/osm.cc b/osm.cc index 7e4e9077a..b1066117d 100644 --- a/osm.cc +++ b/osm.cc @@ -63,7 +63,7 @@ const char* const OsmFormat::osm_features[] = { nullptr }; - /* based on */ +/* based on */ const OsmFormat::osm_icon_mapping_t OsmFormat::osm_icon_mappings[] = { @@ -661,9 +661,9 @@ void OsmFormat::osm_write_tag(const QString& key, const QString& value) const { if (!value.isEmpty()) { - char* str = xml_entitize(CSTR(value)); - gbfprintf(fout, " \n", CSTR(key), str); - xfree(str); + gbfputs(QStringLiteral(" \n") + .arg(key, xml_entitize(value)), + fout); } } diff --git a/util.cc b/util.cc index 362b680a9..b722ee00d 100644 --- a/util.cc +++ b/util.cc @@ -1395,7 +1395,7 @@ entity_types stdentities[] = { }; static -char* +QString entitize(const char* str, bool is_html) { char* p; @@ -1442,19 +1442,21 @@ entitize(const char* str, bool is_html) } } - return (tmp); + QString rv(tmp); + xfree(tmp); + return rv; } /* * Public callers for the above to hide the absence of &apos from HTML */ -char* xml_entitize(const char* str) +QString xml_entitize(const QString& str) { - return entitize(str, false); + return entitize(CSTR(str), false); } -char* html_entitize(const QString& str) +QString html_entitize(const QString& str) { return entitize(CSTR(str), true); } -- 2.30.2